###########################################################################
# 交通仿真程序路网地图窗口
# 作者：张立业
# Copyright: 山东科技大学，交通学院。 All right reserved.
#
##########################################################################
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import config
from trafficlight import TrafficLight
import pub

class MapView( QGraphicsView ):
    def __init__(self, scene):
        super().__init__(scene)
        self.mScene = scene
        self.mMainWnd = None   # Not good

    def mousePressEvent(self, e ):
        '''
        e - QMouseEvent
        '''
        pt = e.pos()
        pt2 = self.mapToScene(pt)
        config.mainwnd.mEditSimOutput.append(" mouse Press Event " + str(pt2))

        x = pt2.x()
        y = pt2.y()

        if self.mMainWnd.mToolState is pub.ToolState.ADD_LIGHT:
            light = TrafficLight( self.mScene, int(x), int(y) )
            light.setState(2)

        elif self.mMainWnd.mToolState is pub.ToolState.PAN:
            self.centerOn(x, y)

    def mouseMoveEvent(self, e):
        if self.mMainWnd.mToolState is pub.ToolState.PAN:
            pt = e.pos()
            pt2 = self.mapToScene(pt)
            config.mainwnd.mEditSimOutput.append(" mouse position " + str(pt2))

            x = pt2.x()
            y = pt2.y()
            self.centerOn(x, y)

    def wheelEvent(self, e):

        config.mainwnd.mEditSimOutput.append(" mouse ----- " + str(e.angleDelta()) )

        # if e.angleDelta() > 0:
        #     self.scale(1.25, 1.25)
        # else:
        #     self.scale(0.8, 0.8)

